import { Component } from 'react'
import { withRouter } from 'react-router-dom'
import { connect } from 'react-redux'
import axios from 'axios'
import { loadData } from '../../actions/user.redux'
//判断用户是否登录
@connect(
  state => state.user,
  {loadData}
)
@withRouter
class AuthRoute extends Component{
  /*constructor(props){
    super(props)
  }*/
  async componentDidMount(){
    const pathname = this.props.location.pathname
    if(pathname ==='/login') {
      return null
    }
    axios.interceptors.response.use((config)=>{
      if(config.data.statusCode===401){
        this.props.history.push('/login')
      }
      return config
    })
    //初始化其它操作
    
    
  }
  render(){
    return null
  }
}

export default AuthRoute